class Solution {
public:
    // 维护两个序列 inc递增序列 dec递减序列 用前缀和思想判断是否符合条件
    vector<int> goodDaysToRobBank(vector<int>& security, int time) {
        int len = security.size();
        vector<int> inc(len), dec(len);
        inc[0] = 1, dec[len - 1] = 1;
        for (int i = 1; i < len; i ++ )
            if (security[i] >= security[i - 1]) inc[i] = inc[i - 1] + 1;
            else inc[i] = 1;
        for (int i = len - 2; i >= 0; i -- )
            if (security[i] >= security[i + 1]) dec[i] = dec[i + 1] + 1;
            else dec[i] = 1;
        vector<int> res;
        for (int i = time; i < len - time; i ++ ) 
            if ((dec[i - time] - dec[i]) >= time && (inc[i + time] - inc[i]) >= time) 
                res.push_back(i);
        return res;
    }
};
